/**
 Search 2nd words of every line with a special condition from a text file. It outputs lines searched
 and the hit count of distinct words.

 @author Susanta Tewari
 @since 12/20/2010
 @version 12/28/2012
 */

/* file containing the words */
final String FILE = "search_2nd_words.txt"

/* holds the distinct words */
final Set words = new HashSet(100)

/* counts the lines searched */
int lineCounter = 0

/**
 * Get the 2nd word. Hit occurs if it has length 1.
 */
new File(FILE).eachLine() { line ->

    lineCounter++

    // get the second word
    def tokens        = line.split("\\s")
    String secondWord = tokens[1]

    // check condition
    if (secondWord.length() == 1) words.add(secondWord)
}

/* print the result */
println "Lines: ${lineCounter}"
println "Distinct Word Hit Count: ${words.size()}"
